package org.zh.client.tra_ds;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import static org.zh.client.config.GlobalStatic.GLOBAL_ThreadLocal;
import static org.zh.client.config.GlobalStatic.getGlobal_TR_ID;
import static org.zh.client.config.ZHOpenInit.httpBasePath;
import static org.zh.util.CommonStatic.om;

@Component
@Aspect
public class ZHOpenTraAdvice {


    @Pointcut("@annotation(org.zh.client.tra_ds.ZHOpenGlobalTra)")
    public void pointCutTX() {
    }

    @Before("pointCutTX()")
    public void before(JoinPoint joinPoint) throws JsonProcessingException {
        RemoteBean rb = new RemoteBean(getGlobal_TR_ID(), System.getProperty(httpBasePath));
        String string = om.writeValueAsString(rb);
        GLOBAL_ThreadLocal.set(string);
    }


}